Here are the steps I have taken to set up a playground area for my own testing of Power BI rest apis
- I set up my own Azure Tenant so that I could have full control of admin
- I set up a new user, like “John Doe” and gave this user Power BI admin privileges in Azure Active Directory blade in portal.azure.com
- Set up a App Registration in Azure. This is the same thing as a Service Principal
- Made a new client secret for the Service Principal and saved it in a notepad (I would have done keyVault but I did not want to sign up for a subscription in Azure)
- Open up Postman and do a Post request to get a token (explained below)
- Use the token to authenticate and call the PBI api (explained below)
5. Postman Post to get Token
Type of URL - POST Main URL Text
https://login.microsoftonline.com/Your Tenant ID here/oauth2/token
And then add this as a Header
Content-Type application/x-www-form-urlencoded
And in the Body of the URL POST call put this in
grant_type=client_credentials
&resource=https://analysis.windows.net/powerbi/api
&client_id=(id of your app reg)
&client_secret=(secret of your app reg)
&scope=https://analysis.windows.net/powerbi/api/.default
This site came in handy when trying to figure this out. Visit here
6. Calling the API with the bearer token
For Postman I did this to get all reports in a Group. A Group in Power BI speak is a workspace.
https://api.powerbi.com/v1.0/myorg/groups/xxgroupidherexx/reports
Just to make it crystal clear for you this is what your CURL code should look like.
curl --location --request GET 'https://api.powerbi.com/v1.0/myorg/groups/7159d753-1ff8-493d-88cf-694165f70707/reports' \
--header 'Authorization: Bearer 'paste your long ass token in here from the previous step (the POST call to get the token)'
--header 'Content-Type: application/json'